Maximum Segment Sum, Monadically (distilled tutorial)

نویسنده

  • Jeremy Gibbons
چکیده

The maximum segment sum problem is to compute, given a list of integers, the largest of the sums of the contiguous segments of that list. This problem specification maps directly onto a cubic-time algorithm; however, there is a very elegant linear-time solution too. The problem is a classic exercise in the mathematics of program construction, illustrating important principles such as calculational development, pointfree reasoning, algebraic structure, and datatype-genericity. Here, we take a sideways look at the datatype-generic version of the problem in terms of monadic functional programming, instead of the traditional relational approach; the presentation is tutorial in style, and leavened with exercises for the reader.

برای دانلود رایگان متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Maximum Segment Sum, Monadically (distilled tutorial, with solutions)

The maximum segment sum problem is to compute, given a list of integers, the largest of the sums of the contiguous segments of that list. This problem specification maps directly onto a cubic-time algorithm; however, there is a very elegant linear-time solution too. The problem is a classic exercise in the mathematics of program construction, illustrating important principles such as calculatio...

متن کامل

An Optimal Algorithm for the Range Maximum-Sum Segment Query Problem

We are given a sequence A of n real numbers which is to be preprocessed. In the Range Maximum-Sum Segment Query (RMSQ) problem, a query is comprised of two intervals [i, j] and [k, l] and our goal is to return the maximum-sum segment of A where the staring index of the segment lies in [i, j] and the ending index lies in [k, l]. We provide the ̄rst known optimal algorithm with O(n) preprocessing...

متن کامل

On the Range Maximum-Sum Segment Query Problem

We are given a sequence A of n real numbers which is to be preprocessed. In the Range Maximum-Sum Segment Query (RMSQ) problem, a query is comprised of two intervals [i, j] and [k, l] and our goal is to return the maximum-sum segment of A whose starting index lies in [i, j] and ending index lies in [k, l]. We propose the first known algorithm for this problem in O(n) preprocessing time and O(1)...

متن کامل

Relative Polynomial Closure and Monadically Krull Monoids of Integer-valued Polynomials

Let D be a Krull domain and Int(D) the ring of integer-valued polynomials on D. For any f ∈ Int(D), we explicitly construct a divisor homomorphism from [[f ]], the divisor-closed submonoid of Int(D) generated by f , to a finite sum of copies of (N0,+). This implies that [[f ]] is a Krull monoid. For V a discrete valuation domain, we give explicit divisor theories of various submonoids of Int(V ...

متن کامل

On a Geometric Approach to the Segment Sum Problem and Its Generalization

Given a sequence of n real numbers a1, a2, a3, . . . , an, the maximum segment sum problem is that of determining indices i and j (1 ≤ i ≤ j ≤ n) such that the sum s(i, j) = ai + ai+1 + . . . + aj is a maximum. Monotone matrices were shown to be remarkably effective in solving several geometric optimization problems. The surprise is that it can also be applied to the above problem as we show he...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 2011